package com.chcplayer.ui
{
import com.chcplayer.enums.UISize;
import com.chcplayer.interfaces.ISizeDisplayObject;
import com.chcplayer.interfaces.ISkinPic;
import com.chcplayer.interfaces.ITextOwner;
import com.chcplayer.skin.BaseButtonSkinState;
import com.chcplayer.skin.BtnDownStateSkin;
import com.chcplayer.skin.BtnUPStateSkin;

import flash.display.SimpleButton;

/**
 * author yh
 */
public class CHSimpleButton extends SimpleButton implements ITextOwner, ISizeDisplayObject
{
	/**
	 */
	private var m_nH:int = UISize.BUTTON_H;
	/**
	 */
	private var m_nW:int;
	/**
	 */
	private var m_strText:String = "";
	/**
	 */
	public function CHSimpleButton()
	{
		super();
		this.hitTestState = new BaseButtonSkinState();
		this.upState = this.overState = new BtnUPStateSkin();
		this.downState = new BtnDownStateSkin();
		this.useHandCursor = false;
	}
//==================================================================================================
// public
//==================================================================================================
	/**
	 */
	public function setText(strT:String):void
	{
		if ( strT != null )
		{
			m_strText = strT;
			this.setSizeWH(m_nW, m_nH);
			if ( this.upState is ITextOwner )
			{
				ITextOwner(this.upState).setText(m_strText);
			}
			if ( this.overState is ISizeDisplayObject )
			{
				ITextOwner(this.overState).setText(m_strText);
			}
			if ( this.downState is ISizeDisplayObject )
			{
				ITextOwner(this.downState).setText(m_strText);
			}
		}
	}
	/**
	 */
	public function getText():String
	{
		return m_strText;
	}
	/**
	 */
	public function setWidth(nW:int):void
	{
		this.setSizeWH(nW, m_nH);
	}
	/**
	 */
	public function setHeight(nH:int):void
	{
		this.setSizeWH(m_nW, nH);
	}
	/**
	 */
	public function setSizeWH(nW:int, nH:int):void
	{
		m_nW = nW;
		m_nH = nH;
		if ( this.hitTestState is ISkinPic )
		{
			ISkinPic(this.hitTestState).setSizeWH(nW, nH);
		}
		if ( this.upState is ISizeDisplayObject )
		{
			ISkinPic(this.upState).setSizeWH(nW, nH);
		}
		if ( this.overState is ISizeDisplayObject )
		{
			ISkinPic(this.overState).setSizeWH(nW, nH);
		}
		if ( this.downState is ISizeDisplayObject )
		{
			ISkinPic(this.downState).setSizeWH(nW, nH);
		}
	}
	/**
	 */
	public function fit2SkinSize():void
	{
		var nW:int = ISkinPic(this.upState).getDefaultWidth();
		var nH:int = ISkinPic(this.upState).getDefaultHeight();
		this.setSizeWH(nW, nH);
	}
	/**
	 */
	public function setEnabled(bl:Boolean):void
	{
		if ( bl )
		{
			this.alpha = 1;
			this.mouseEnabled = true;
		}
		else
		{
			this.alpha = .5; 
			this.mouseEnabled = false;
		}
	}
	/**
	 */
	override public function get width():Number
	{
		return m_nW;
	}
	/**
	 */
	override public function get height():Number
	{
		return m_nH;
	}
	/**
	 */
	override public function set width(nW:Number):void
	{
		this.setSizeWH(nW, m_nH);
	}
	/**
	 */
	override public function set height(nH:Number):void
	{
		this.setSizeWH(m_nW, nH);
	}
	/**
	 */
}
}